<template>
  <el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="Dialog Titile">
    <el-row :gutter="32">
      <el-form ref="短信添加" :model="formData" :rules="rules" size="medium" label-width="100px"
               label-position="left">
        <el-col :span="20">
          <el-form-item label="模板名称" prop="templateName">
            <el-input v-model="formData.templateName" placeholder="请输入模板名称" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item label="模板内容" prop="templateContent">
            <el-input v-model="formData.templateContent" type="textarea"
                      placeholder="例:您的验证码${code},该验证码5分钟内有效，请勿泄漏于他人！" :autosize="{minRows: 4, maxRows: 4}"
                      :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item label="模板类型" prop="templateType">
            <el-select v-model="formData.templateType" placeholder="请选择模板类型" clearable :style="{width: '100%'}">
              <el-option v-for="(item, index) in templateTypeOptions" :key="index" :label="item.label"
                         :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item label="code参数" prop="templateParam">
            <el-input v-model="formData.templateParam" placeholder="多个用逗号隔开,例code,massage,(无参可不填,仅限短信通知类型)"
                      clearable :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item label="申请说明" prop="templdateExplain">
            <el-input v-model="formData.templdateExplain" type="textarea" placeholder="请输入申请说明"
                      :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <div slot="footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="handelConfirm">确定</el-button>
    </div>
  </el-dialog>
</template>

<style>

</style>

<script>

import axios from "axios"
import rules from "../../utils/rules"
export default {
  inheritAttrs: false,
  components: {},
  props: ["closeAdd","init","admin"],
  data() {
    return {
      formData: {
        templateName: undefined,
        templateContent: "",
        templateType: 0,
        templateParam: undefined,
        templdateExplain: "",
      },
      rules: {
        templateName: [{
          required: true,
          message: '请输入模板名称',
          trigger: 'blur'
        }],
        templateContent: [{
          required: true,
          message: '例:您的验证码${code},该验证码5分钟内有效，请勿泄漏于他人！',
          trigger: 'blur'
        }],
        templateType: [{
          required: true,
          message: '请选择模板类型',
          trigger: 'change'
        }],
        templateParam: [],
        templdateExplain: [{
          required: true,
          message: '请输入申请说明',
          trigger: 'blur'
        }],
      },
      templateTypeOptions: [{
        "label": "验证码",
        "value": 0
      }, {
        "label": "短信通知",
        "value": 1
      }, {
        "label": "国际/港澳台消息",
        "value": 3
      }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {

  },
  methods: {
    onOpen() {},
    onClose() {
      this.$refs['短信添加'].resetFields()
    },
    close() {
      this.$emit('update:visible', false)
    },
    handelConfirm() {

      this.$refs['短信添加'].validate(valid => {
        if (!valid) return
        axios.post("http://localhost:8103/shortMessage",{
          templateName: this.formData.templateName,
          templateContent: this.formData.templateContent,
          templateType: this.formData.templateType,
          templateParam: this.formData.templateParam,
          templdateExplain: this.formData.templdateExplain,
          tepmlateCreateUser: this.admin.adminId,
          templateUpdateUser:this.admin.adminId
        }).then((data)=>{
          console.log(data,"-------------")

          if(data.data.msg == "执行成功"){
            this.$message({
              type: 'success',
              message: '添加成功!'
            })
          }
          this.init();
          this.closeAdd();
          this.close();
        })
      })
    },
  }
}

</script>
